package com.senlingspace.system.service.impl;

import java.util.Date;
import java.util.List;

import com.senlingspace.common.exception.UtilException;
import com.senlingspace.common.utils.DateUtils;
import com.senlingspace.common.utils.SecurityUtils;
import com.senlingspace.system.domain.SlkjShopOperate;
import com.senlingspace.system.domain.dto.FzShopPosDto;
import com.senlingspace.system.domain.vo.SharesPosVo;
import com.senlingspace.system.mapper.SlkjShopOperateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.senlingspace.system.mapper.SlkjShopPosMapper;
import com.senlingspace.system.domain.SlkjShopPos;
import com.senlingspace.system.service.ISlkjShopPosService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 分账比例-门店pos关系Service业务层处理
 * 
 * @author wangliang
 * @date 2024-07-15
 */
@Service
public class SlkjShopPosServiceImpl implements ISlkjShopPosService 
{
    @Autowired
    private SlkjShopPosMapper slkjShopPosMapper;
    @Autowired
    private SlkjShopOperateMapper operateMapper;

    /**
     * 查询分账比例-门店pos关系
     * 
     * @param id 分账比例-门店pos关系主键
     * @return 分账比例-门店pos关系
     */
    @Override
    public SlkjShopPos selectSlkjShopPosById(Long id)
    {
        return slkjShopPosMapper.selectSlkjShopPosById(id);
    }

    /**
     * 查询分账比例-门店pos关系列表
     * 
     * @param slkjShopPos 分账比例-门店pos关系
     * @return 分账比例-门店pos关系
     */
    @Override
    public List<SlkjShopPos> selectSlkjShopPosList(SlkjShopPos slkjShopPos)
    {
        return slkjShopPosMapper.selectSlkjShopPosList(slkjShopPos);
    }

    /**
     * 新增分账比例-门店pos关系
     * 
     * @param slkjShopPos 分账比例-门店pos关系
     * @return 结果
     */
    @Override
    public int insertSlkjShopPos(SlkjShopPos slkjShopPos)
    {
        slkjShopPos.setCreateTime(DateUtils.getNowDate());
        return slkjShopPosMapper.insertSlkjShopPos(slkjShopPos);
    }

    /**
     * 修改分账比例-门店pos关系
     * 
     * @param slkjShopPos 分账比例-门店pos关系
     * @return 结果
     */
    @Override
    public int updateSlkjShopPos(SlkjShopPos slkjShopPos)
    {
        slkjShopPos.setUpdateTime(DateUtils.getNowDate());
        return slkjShopPosMapper.updateSlkjShopPos(slkjShopPos);
    }

    /**
     * 批量删除分账比例-门店pos关系
     * 
     * @param ids 需要删除的分账比例-门店pos关系主键
     * @return 结果
     */
    @Override
    public int deleteSlkjShopPosByIds(Long[] ids)
    {
        return slkjShopPosMapper.deleteSlkjShopPosByIds(ids);
    }

    /**
     * 删除分账比例-门店pos关系信息
     * 
     * @param id 分账比例-门店pos关系主键
     * @return 结果
     */
    @Override
    public int deleteSlkjShopPosById(Long id)
    {
        return slkjShopPosMapper.deleteSlkjShopPosById(id);
    }

    /**
     *
     *
     * @author wangliang
     * @param shopId
     * @return
     */
    @Override
    public SharesPosVo selectPosShopByShopId(Long shopId) {
        return slkjShopPosMapper.selectPosShopByShopId(shopId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateSlkjShopPosDto(FzShopPosDto posDto) {
        posDto.setUpdateBy(SecurityUtils.getUsername());
        posDto.setUpdateTime(DateUtils.getNowDate());
        int posNum = slkjShopPosMapper.updateSlkjShopPosDto(posDto);
        SlkjShopOperate shopOperate = new SlkjShopOperate();
        shopOperate.setId(posDto.getOperateId());
        shopOperate.setInvestorBefore(posDto.getOperateBefore());
        shopOperate.setInvestorAfter(posDto.getOperateAfter());
        shopOperate.setUpdateBy(SecurityUtils.getUsername());
        shopOperate.setUpdateTime(DateUtils.getNowDate());
        int operateNum = operateMapper.updateSlkjShopOperate(shopOperate);
        if(operateNum == 0 || posNum == 0 ){
            throw new UtilException("修改数据失败");
        }
        return posNum;
    }
}
